package com.panopset.nls;

import java.util.HashMap;
import java.util.Map;

import javax.swing.ImageIcon;

/**
 * Name, flag, and locale of a language.
 *
 * @author Karl Dinwiddie
 *
 */
public class Language {
    private static Map<String, Language> languages = new HashMap<String, Language>();
    private final String localeName;
    private Map<String,String> names;
    private final ImageIcon flagImage;

    static {
        for (String ln : FlagIcons.asFlagIcons().spritePackage.getResourceList()) {
            languages.put(ln, new Language(ln));
        }
    }

    private Language(String localeName) {
        this.localeName = localeName;
        this.flagImage = FlagIcons.asFlagIcons().getFlag(localeName);
    }

    public static Language getLanguage(String localeName) {
        return languages.get(localeName);
    }

    public ImageIcon getFlagImage() {
        return flagImage;
    }

    public String getLocaleName() {
        return localeName;
    }

    private Map<String, String> getNames() {
        if (names == null) {
            names = new HashMap<String, String>();
        }
        return names;
    }
}
